﻿/*
 * @author rayzhang
 * @desc: 简易的qss预处理器
 */
#pragma once

#include <QString>
#include <QVariantMap>
#include "types.h"
#include "qtheme_global.h"
namespace qui::qless
{
class LIBQTHEME_API Parser
{
private:
    QString _filename;
    // 解析的变量
    QVariantMap _variables;

public:
    Parser(QString filename, QVariantMap initVariables = {});
    QString parse();
    QVariantMap variables() const { return _variables; }
    QVariant variable(QString name, const QVariant& defaultValue) const;

private:
    // 读取样式表文件内容
    StyleSheets parseFile(const QString& styleFile);
    StyleSheets parseImport(const QString& currentFilePath, QString statement);
    void parseVariable(const QString& statement);
    void applyVariables(QString& statement) const;
    void parseFunctions(QString& statement);

    static void compileSelector(const std::shared_ptr<Selector>& selector, QString& qss);
    static QString compile(const StyleSheets& styleSheets);
};
} // namespace qui::qless
